<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Day Page</title>
</head>

<body>

</body>
<script>
    //计算某日是该年的第几天
    var year = prompt("请输入年份:");
    var month = prompt("请输入月份:");
    var day = prompt("请输入日期:");
    var sum = 0;
    var dayArr = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    // 判断输入是否正确
    if (year == "" || year == null || month == "" || month == null || day == "" || day == null) {
        alert("输入错误，请重新输入！");
        location.reload();
    } else if (year < 0 || month < 1 || month > 12 || day < 1 || day > 31) {
        alert("输入错误，请重新输入！");
        location.reload();
    }else {
        // 将输入的字符串转化为整数类型
        year = parseInt(year);
        month = parseInt(month);
        day = parseInt(day);
        // 闰年二月份有29天
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
            dayArr[1] = 29;
        }
        for (var i = 0; i < month - 1; i++) {
            sum += dayArr[i];
        }
    }
    sum += day;
    document.write(year + "年" + month + "月" + day + "日是" + year + "年的第" + sum + "天");
    document.write('<br>')
</script>

</html>